# nums = [1,3,2,2,5,2,3,7]
# nums = [1,1,1,1]
nums = [1,2,3,4]
def findLHS(nums):
    numsLength=len(nums)
    if numsLength<=1:
        return 0
    nums.sort()
    print(nums)
    l_pointer=0
    r_pointer=1
    is_have=False
    res=0
    while l_pointer<numsLength and r_pointer<numsLength and l_pointer<=r_pointer:
        max,min=nums[r_pointer],nums[l_pointer]
        if max-min==0:
            r_pointer+=1
        if max-min==1:
            #符合要求
            r_pointer+=1
            is_have=True
        if max-min>1:
            if is_have:
                if res<r_pointer-l_pointer:
                    res=r_pointer-l_pointer
                is_have=False

            l_pointer+=1
    if is_have:
        if res<r_pointer-l_pointer:
            res=r_pointer-l_pointer

    return res
print(findLHS(nums))